package com.richpay.basejava.base13.factory;

public class SimpleFactory {
    public static Person getInstance(String type) {
        if ("worker".equals(type)) {
            return new Worker();
        } else if ("peasant".equals(type)) {
            return new Peasant();
        } else if ("doctor".equals(type)) {
            return new Doctor();
        } else {
            throw new RuntimeException("无效的类型字符串:" + type);
        }

        /**
         * zhangjunyangdeMacBook-Pro:factory Young$ java com.richpay.basejava.base13.factory.TestDemo
         * Exception in thread "main" java.lang.RuntimeException: 无效的类型字符串:test
         * 	at com.richpay.basejava.base13.factory.SimpleFactory.getInstance(SimpleFactory.java:12)
         * 	at com.richpay.basejava.base13.factory.TestDemo.main(TestDemo.java:9)
         */
    }
}
